package com.example.project22_editingmediaplayer;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.example.minimusicdemo.Main_play;
import com.example.project22_editingmediaplayer.adapter.AdapterListOfAlbum;
import com.example.project22_editingmediaplayer.objects.listalbumObject;

public class LayoutPlaylist extends Fragment {
	ArrayList<listalbumObject> arrayListalbum = new ArrayList<listalbumObject>();
	ListView list_playlist;
	AdapterListOfAlbum adapterlist_album;

	public static Fragment newInstance(Context context) {
		LayoutPlaylist f = new LayoutPlaylist();

		return f;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		ViewGroup root = (ViewGroup) inflater.inflate(R.layout.layout_playlist,
				null);
		list_playlist = (ListView) root.findViewById(R.id.list_playlist);

		// listalbumObject listalbumObject=new listalbumObject(1, "Favorite");
		if (arrayListalbum.size() == 0) {
			arrayListalbum.add(new listalbumObject(1, "Favorite",
					R.drawable.favoritealbum));
			arrayListalbum.add(new listalbumObject(1, "Happy",
					R.drawable.happyminion));
			arrayListalbum.add(new listalbumObject(1, "Funny",
					R.drawable.funnyminion));
			arrayListalbum.add(new listalbumObject(1, "Sad",
					R.drawable.sadminion));
			arrayListalbum.add(new listalbumObject(1, "Rating",
					R.drawable.sadminion));
		}
		adapterlist_album = new AdapterListOfAlbum(arrayListalbum,
				getActivity());
		list_playlist.setAdapter(adapterlist_album);
		adapterlist_album.notifyDataSetChanged();
		registerForContextMenu(list_playlist);
		list_playlist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				if (arg2 == 4) {
					Intent intent = new Intent(getActivity(),
							PlayListByRating.class);
					getActivity().startActivity(intent);
				} else {
					Intent intent = new Intent(getActivity(),
							PlaylistAlbumDetail.class);
					intent.putExtra("position", arg2);
					getActivity().startActivity(intent);
				}
			}
		});
		return root;
	}

	@Override
	public boolean onContextItemSelected(MenuItem item) {
		// TODO Auto-generated method stub

		if (item.getTitle() == "Play All") {
			playall();
		} else if (item.getTitle() == "Delete Playlist") {
			deleteplaylist();
		} else if (item.getTitle() == "Rename Playlist") {
			renameplaylist();
		} else {
			return false;
		}
		return true;

	}

	private void renameplaylist() {
		// TODO Auto-generated method stub

	}

	private void deleteplaylist() {
		// TODO Auto-generated method stub

	}

	private void playall() {
		// TODO Auto-generated method stub

	}
}
